﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="TfsWorkbench.UIElements.FilterObjects.FilterTreeView"
    x:Name="PART_ComboBoxTreeView" 
    mc:Ignorable="d" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:filterObjects="clr-namespace:TfsWorkbench.UIElements.FilterObjects">
    <UserControl.Resources>
    	<ResourceDictionary>
    		<ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/ApplicationStyles.xaml"/>
                <ResourceDictionary Source="/TfsWorkbench.UIElements;Component/Resources/CommandButtonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <HierarchicalDataTemplate x:Key="NodeTemplate" DataType="{x:Type filterObjects:IFilterItem}" ItemsSource="{Binding ChildFilters}">
                <StackPanel Orientation="Horizontal">
                    <CheckBox IsChecked="{Binding Mode=TwoWay, Path=IsSelected}" VerticalAlignment="Center">
                        <TextBlock Text="{Binding DisplayText}" />
                    </CheckBox>
                </StackPanel>
    		</HierarchicalDataTemplate>
    	</ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Popup 
            PopupAnimation="Fade"
            x:Name="PART_TreeViewPopup"
            AllowsTransparency="True"
            Placement="Bottom"
            PlacementTarget="{Binding ElementName=PART_ComboBoxTreeView}"
            >
            <TreeView 
                x:Name="PART_MainTreeView"
                KeyDown="OnTreeViewKeyDown"
                ItemTemplate="{StaticResource NodeTemplate}"
                ItemsSource="{Binding ElementName=PART_ComboBoxTreeView, Path=FilterCollection}"
                MinWidth="200"
                MinHeight="250"
                />
        </Popup>
        <ToggleButton 
			x:Name="PART_ToggleButton" 
			HorizontalContentAlignment="Stretch"
			Checked="OnShowPopup" 
			IsChecked="{Binding IsOpen, ElementName=PART_TreeViewPopup}"
			>
        	<Grid>
        		<Grid.ColumnDefinitions>
                    <ColumnDefinition Width="16" />
                    <ColumnDefinition />
        			<ColumnDefinition Width="16" />
        		</Grid.ColumnDefinitions>
                <ContentControl IsTabStop="False" Template="{StaticResource AddIconTemplate}" Margin="2" Foreground="{StaticResource ButtonNormalStroke}" />
                <TextBlock Grid.Column="1" TextAlignment="Left">
                    <TextBlock Text="{Binding ElementName=PART_ComboBoxTreeView, Path=SelectedItemCount, StringFormat={}Work Items ({0})}" />
                </TextBlock>
                <Rectangle Margin="0" Fill="{StaticResource Arrow}" Width="8" Height="4" Grid.Column="2" />
        	</Grid>
        </ToggleButton>
    </Grid>
</UserControl>
